<?php
$id = '';
if (isset($_GET["id"])){
  $id = $_GET["id"];
}
?>
<?php
$servername = "mysql";
$username = "root";
$password = "password";
$dbname = "test";

// ��������
$conn = new mysqli($servername, $username, $password, $dbname);
// �������
if ($conn->connect_error) {
  die("����ʧ��: " . $conn->connect_error);
}

$sql = "SELECT id, name, description FROM task where id='$id'";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
  // ���ÿ������
  while($row = $result->fetch_assoc()) {
    $id = $row["id"];
    $name = $row["name"];
    $description = $row["description"];
  }
}
$conn->close();
?>
<?php
if (!$id):
  ?>
  <form action="/task/manager.php" method="post">

    <input type="text" name="name" value="">
    <input type="text" name="description" value="">
    <input type="submit" value="增加">
  </form>
  <?php
endif;
?>

<?php
if ($id):
  ?>
  <form action="/task/manager.php" method="post">
    <input type="hidden" name="id" value="<?php echo $id; ?>">

    <input type="text" name="name" value="<?php echo $name; ?>">
    <input type="text" name="description" value="<?php echo $description; ?>">
    <input type="submit" value="更新">
  </form>
  <?php
endif;
?>
<ul>
  <li><a href="/task/task_form.php">新增</a></li>
  <li><a href="/task/list.php">列表</a></li>
</ul>